﻿<!--
	========================================================================
	 awzBoxes Library
	
	 Homepage: http://www.awzhome.de/
	========================================================================
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of awzBoxes Library.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2011-2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	========================================================================
-->

<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:box="clr-namespace:AWZhome.awzBoxes"
	xmlns:boxt="clr-namespace:AWZhome.awzBoxes.Tools">

	<boxt:PercentConverter x:Key="PercentConverter" />
	<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
	<boxt:BoxItemDockOptionConverter x:Key="FloatingDockOptionConverter" ComparedValue="Floating" />

	<SolidColorBrush x:Key="MouseDraggedOverTabBackgroundBrush">
		<SolidColorBrush.Color>
			<Color R="255" G="0" B="0" A="20" />
		</SolidColorBrush.Color>
	</SolidColorBrush>

	<SolidColorBrush x:Key="MouseDraggedOverTabTextBrush">
		<SolidColorBrush.Color>
			<Color R="220" G="0" B="0" A="255" />
		</SolidColorBrush.Color>
	</SolidColorBrush>
	
	<!-- Style of the Box control -->
	<Style TargetType="box:Box">
		<Setter Property="Background" Value="Transparent" />
		<Setter Property="BorderBrush" Value="Red" />
	</Style>

	<!-- Style of the TabControl itself -->
	<Style TargetType="{x:Type TabControl}">
		<Style.Triggers>
			<DataTrigger Binding="{Binding IsSideBar}" Value="True">
				<Setter Property="TabStripPlacement" Value="Bottom" />
			</DataTrigger>
			<DataTrigger Binding="{Binding IsSideBar}" Value="False">
				<Setter Property="TabStripPlacement" Value="Top" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style of TabItem header text -->
	<Style TargetType="{x:Type TextBlock}" x:Key="HeaderTextStyle">
		<Style.Triggers>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsActive}" Value="True" />
					<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type box:Box}}, Path=IsSideBar}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="FontWeight" Value="Bold" />
			</MultiDataTrigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
			</MultiDataTrigger>
			<DataTrigger Binding="{Binding IsMouseDraggedOver}" Value="True">
				<Setter Property="Foreground" Value="{StaticResource MouseDraggedOverTabTextBrush}" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style of the little asterisk before TabItem header text indicating "dirty" (= changed) files -->
	<Style TargetType="{x:Type TextBlock}" x:Key="HeaderDirtyAsteriskStyle">
		<Style.Triggers>
			<DataTrigger Binding="{Binding IsChanged}" Value="True">
				<Setter Property="Visibility" Value="Visible" />
			</DataTrigger>
			<DataTrigger Binding="{Binding IsLocallyActive}" Value="True">
				<Setter Property="FontWeight" Value="Bold" />
			</DataTrigger>
			<DataTrigger Binding="{Binding IsChanged}" Value="False">
				<Setter Property="Visibility" Value="Collapsed" />
			</DataTrigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
			</MultiDataTrigger>
			<DataTrigger Binding="{Binding IsMouseDraggedOver}" Value="True">
				<Setter Property="Foreground" Value="{StaticResource MouseDraggedOverTabTextBrush}" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style for the Image element displaying BoxItem's icon -->
	<Style TargetType="{x:Type Image}" x:Key="TabItemIconStyle">
		<Style.Triggers>
			<DataTrigger Binding="{Binding IsHighlighted}" Value="True">
				<DataTrigger.EnterActions>
					<BeginStoryboard Name="BlinkingIconStoryboard">
						<Storyboard>
							<DoubleAnimation
									RepeatBehavior="Forever" AutoReverse="True"
									From="1" To="0" Duration="0:0:0.75"
									Storyboard.TargetProperty="Opacity" />
						</Storyboard>
					</BeginStoryboard>
				</DataTrigger.EnterActions>
			</DataTrigger>
			<DataTrigger Binding="{Binding IsHighlighted}" Value="False">
				<DataTrigger.EnterActions>
					<StopStoryboard BeginStoryboardName="BlinkingIconStoryboard" />
				</DataTrigger.EnterActions>
				<Setter Property="Opacity" Value="1" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style of the progress bar in TabItems -->
	<Style TargetType="{x:Type StackPanel}" x:Key="TabItemProgressBarStyle">
		<Style.Triggers>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Background" Value="{x:Static SystemColors.HighlightTextBrush}" />
			</MultiDataTrigger>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="True" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
			</MultiDataTrigger>
			<DataTrigger Binding="{Binding IsHighlighted}" Value="False">
				<Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style for tab buttons -->
	<Style x:Key="TabItemHeaderButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
		<Setter Property="VerticalAlignment" Value="Center" />
		<Setter Property="HorizontalAlignment" Value="Right" />
		<Setter Property="Width" Value="16" />
		<Setter Property="Height" Value="16" />
		<Setter Property="Padding" Value="0,0,0,0" />
		<Setter Property="Focusable" Value="False" />
		<Style.Triggers>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
			</MultiDataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Template of the complete TabItem header -->
	<DataTemplate x:Key="TabItemHeaderTemplate">
		<Grid>
			<!-- The StackPanel here imitates a little progress bar -->
			<StackPanel Height="16" Margin="0,0,0,0" VerticalAlignment="Center"
								Style="{StaticResource TabItemProgressBarStyle}" Opacity="0.35">
				<StackPanel.RenderTransform>
					<ScaleTransform ScaleX="{Binding Path=Progress, Converter={StaticResource PercentConverter}}" />
				</StackPanel.RenderTransform>
			</StackPanel>
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition MinWidth="0" MaxWidth="16" />
					<ColumnDefinition />
					<ColumnDefinition />
					<ColumnDefinition Width="7" />
					<ColumnDefinition />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>
				<Image
						Grid.Column="0" VerticalAlignment="Center"
						Height="16" Style="{StaticResource TabItemIconStyle}"
						Source="{Binding Icon}" ToolTip="{Binding ToolTip}" />
				<TextBlock Grid.Column="1" Text="* " Style="{StaticResource HeaderDirtyAsteriskStyle}" ToolTip="{Binding ToolTip}"></TextBlock>
				<TextBlock Grid.Column="2" Text="{Binding Title}" Style="{StaticResource HeaderTextStyle}" ToolTip="{Binding ToolTip}"></TextBlock>
				<Button
						Grid.Column="4" FontFamily="Wingdings" Margin="0,0,0,0" Padding="0,0,0,0"
						Style="{StaticResource TabItemHeaderButtonStyle}"
						Visibility="{Binding Path=AllowedDockAreas, Converter={StaticResource FloatingDockOptionConverter}}"
						Command="box:BoxCommands.BoxItemFloating">ä</Button>
				<Button
						Grid.Column="5" FontFamily="Marlett" Margin="0,0,0,0" Padding="0,0,0,0"
						Style="{StaticResource TabItemHeaderButtonStyle}"
						Visibility="{Binding Path=IsClosable, Converter={StaticResource BooleanToVisibilityConverter}}"
						Command="box:BoxCommands.BoxItemClose">r</Button>
			</Grid>
		</Grid>
	</DataTemplate>

	<!-- Style of TabItem elements (mapping content of BoxItem and setting header template) -->
	<Style TargetType="{x:Type TabItem}">
		<Setter Property="Content" Value="{Binding Content}" />
		<Setter Property="HeaderTemplate" Value="{Binding Source={StaticResource TabItemHeaderTemplate}}" />
		<Setter Property="AllowDrop" Value="True" />
		<Setter Property="IsSelected" Value="{Binding Path=IsLocallyActive, Mode=TwoWay}" />
		<Style.Triggers>
			<MultiDataTrigger>
				<MultiDataTrigger.Conditions>
					<Condition Binding="{Binding IsHighlighted}" Value="True" />
					<Condition Binding="{Binding IsLocallyActive}" Value="False" />
				</MultiDataTrigger.Conditions>
				<Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
			</MultiDataTrigger>
			<DataTrigger Binding="{Binding IsMouseDraggedOver}" Value="True">
				<Setter Property="Background" Value="{StaticResource MouseDraggedOverTabBackgroundBrush}" />
			</DataTrigger>
		</Style.Triggers>
	</Style>

	<!-- Style of the DragOverlayBox -->
	<Style TargetType="{x:Type boxt:DragOverlayBox}">
		<Setter Property="Margin" Value="3,35,3,3" />
	</Style>

	<!-- Style of the title bar for side bars -->
	<Style TargetType="{x:Type Label}" x:Key="SideBarTitleStyle">
		<Setter Property="Foreground" Value="{x:Static SystemColors.ActiveCaptionTextBrush}" />
		<Setter Property="HorizontalContentAlignment" Value="Stretch" />
		<Setter Property="VerticalContentAlignment" Value="Stretch" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Label}">
					<Border Background="{x:Static SystemColors.ActiveCaptionBrush}" CornerRadius="3,3,0,0">
						<Grid Margin="2,2,2,2">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="*" />
								<ColumnDefinition Width="7" />
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition Width="Auto" />
							</Grid.ColumnDefinitions>
							<ContentPresenter
									Grid.Column="0"
									HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
									VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
									RecognizesAccessKey="True" />
							<Button
									Grid.Column="2" FontFamily="Marlett" Margin="0,0,0,0" Padding="0,0,0,0"
									Foreground="{x:Static SystemColors.ActiveCaptionTextBrush}"
									Style="{StaticResource TabItemHeaderButtonStyle}"
									Command="box:BoxCommands.BoxAutoHide"
									Visibility="{Binding
										ElementName=BoxItemTabControl,
										Path=SelectedItem.IsAutoHideAllowed,
										Converter={StaticResource BooleanToVisibilityConverter}}">7</Button>
							<Button
									Grid.Column="3" FontFamily="Wingdings" Margin="0,0,0,0" Padding="0,0,0,0"
									Foreground="{x:Static SystemColors.ActiveCaptionTextBrush}"
									Style="{StaticResource TabItemHeaderButtonStyle}"
									Command="box:BoxCommands.BoxItemFloating"
									Visibility="{Binding
										ElementName=BoxItemTabControl,
										Path=SelectedItem.AllowedDockAreas,
										Converter={StaticResource FloatingDockOptionConverter}}">ä</Button>
							<Button
									Grid.Column="4" FontFamily="Marlett" Margin="0,0,0,0" Padding="0,0,0,0"
									Foreground="{x:Static SystemColors.ActiveCaptionTextBrush}"
									Style="{StaticResource TabItemHeaderButtonStyle}"
									Command="box:BoxCommands.BoxItemClose"
									Visibility="{Binding
										ElementName=BoxItemTabControl,
										Path=SelectedItem.IsClosable,
										Converter={StaticResource BooleanToVisibilityConverter}}">r</Button>
						</Grid>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>